package com.wz.controller;

import com.wz.pojo.Transaction;
import com.wz.service.BlockService;
import com.wz.service.TransactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rx.Subscription;

import java.math.BigInteger;
import java.util.HashMap;

/**
 * @program: demo
 * @description: 交易相关
 * @author: Wangzheng
 * @create: 2020-12-22 19:47
 **/
@RestController
@RequestMapping("/TransactionDemo")
public class TransactionDemo {

	@Autowired
	private static Subscription subscription;

	@Autowired
	private BlockService blockService;

	@Autowired
	private TransactionService transactionService;

	//拿初始数据
	@RequestMapping("/getOriginTransactionData")
	public HashMap<String, Object> getTransaction() {
		return transactionService.getTransactionDataToMap();
	}

	//拿pojo数据
	@RequestMapping("/getTransactionData")
	public HashMap<Integer, Transaction> getTransactionData() {

		try {
			return transactionService.getTransactionDataToPojo();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}

	}

	//插数据库
	@RequestMapping("/insertTransactionDataToDB")
	public String insertTransactionDataToDB() {
		try {
			return transactionService.insertTransactionData();
		} catch (Exception e) {
			e.printStackTrace();
			return "失败";
		}
	}


	//插数据库//  
	@RequestMapping("/insert")
	public void insert() {
		try {
			transactionService.insertDB();
		} catch (Exception e) {
			e.printStackTrace();
			
		}
	}
	
	
	//接受监听到的最高块号来插库
	@RequestMapping("/insertDBByLASTEST")
	public void insertDBByLASTEST(BigInteger num){
		
		
		transactionService.insertDBByLastBlockNum(num);
		
	}


}